<?php
class RedisDriver {

    public $data_redis;
    public $cache_redis;

    public function initDataRedis($uid) {
        $mod = Config::$mod;

        $redis_config = Config::$redis_data_config;
        //$redis_name = 'redis'.($uid % $mod);
        $redis_name = 'redis0';
        $this->data_redis = new redis();
        $ret = $this->data_redis->connect($redis_config[$redis_name]['host'],$redis_config[$redis_name]['port']);
        if (!$ret) {
			return false;
        }

        $ret = $this->data_redis->auth($redis_config[$redis_name]['pass']);
        if (!$ret) {
			return false;
		}
		return true;
    }

    public function initCacheRedis() {
        $mod = Config::$mod;
        $redis_config = Config::$redis_data_config;
        //$redis_name = 'redis'.($uid % $mod);
        $redis_name = 'redis0';
        $this->cache_redis = new redis();
        $ret = $this->cache_redis->connect($redis_config[$redis_name]['host'],$redis_config[$redis_name]['port']);
        if (!$ret) {
			return false;
        }

        $ret = $this->cache_redis->auth($redis_config[$redis_name]['pass']);
        if (!$ret) {
			return false;
		}
		$this->cache_redis->select(2);
		return true;
    }

    public function deinitDataRedis() {
        $this->data_redis->close();
    }

    public function deinitCacheRedis() {
        $this->cache_redis->close();
    }

}

?>
